const path = require('path')
const fs = require('fs')
const sharp = require('sharp')
module.exports = async (ctx,next) => {
  const filepath = path.join('storage',path.sep, ctx.params.date, path.sep, ctx.params.file)
  const image = sharp(filepath)
  let stat = await fs.statSync(filepath)
  let metadata = await image.metadata()
  ctx.body = {
    name: ctx.params.file,
    date: ctx.params.date,
    size: stat.size,
    mtime: stat.mtime,
    path: filepath,
    width: metadata.width,
    height: metadata.height,
    format: metadata.format,
    cache: 'cache/',
    url: ctx.protocol + '://' + ctx.host + ctx.path.substr(5)
  }
}